<template>
  <div>
    <header class="header">
      <comp-header>
        <template v-slot:ctitle>购物</template>
        <template v-slot:cicon
          ><span class="fa fa-align-justify"></span
        ></template>
      </comp-header>
      <div class="search">
        <div><span class="shopping-car fa fa-shopping-cart"></span></div>
        <div class="search-box">
          <span class="search-icon fa fa-search"></span>
          <input
            type="text"
            placeholder="搜索"
            v-model="searchley"
            @keyup.enter="getDataSearch()"
          />
        </div>
      </div>
    </header>
    <div class="types">
      <ul>
        <li>
          <a href="javascript:;">
            <span class="icon"></span>
            <span class="text">家电馆</span>
          </a>
        </li>
        <li>
          <a href="javascript:;">
            <span class="icon"></span>
            <span class="text">美食馆</span>
          </a>
        </li>
        <li>
          <a href="javascript:;">
            <span class="icon"></span>
            <span class="text">家居馆</span>
          </a>
        </li>
        <li>
          <a href="javascript:;">
            <span class="icon"></span>
            <span class="text">时尚馆</span>
          </a>
        </li>
        <li>
          <a href="javascript:;">
            <span class="icon"></span>
            <span class="text">海外购</span>
          </a>
        </li>
        <li>
          <a href="javascript:;">
            <span class="icon"></span>
            <span class="text">限时抢购</span>
          </a>
        </li>
        <li>
          <a href="javascript:;">
            <span class="icon"></span>
            <span class="text">科技馆</span>
          </a>
        </li>
        <li>
          <a href="javascript:;">
            <span class="icon"></span>
            <span class="text">电子票券</span>
          </a>
        </li>
        <li>
          <a href="javascript:;">
            <span class="icon"></span>
            <span class="text">户外运动</span>
          </a>
        </li>
        <li>
          <a href="javascript:;">
            <span class="icon"></span>
            <span class="text">全部分类</span>
          </a>
        </li>
      </ul>
    </div>
    <comp-title-second>
      <template v-slot:title>热销商品</template>
      <template v-slot:mome
        >查看更多<span class="fa fa-caret-right"></span
      ></template>
    </comp-title-second>
    <div class="product-list">
      <ul>
        <li v-for="item in arrrxsp" :key="item.id">
          <div class="top">
            <img v-lazy="item.pict_url" alt="" />
          </div>
          <div class="bottom">
            <div class="product-name">{{ item.title }}</div>
            <div class="youhui">
              <div class="quan">
                <span class="baoyou">包邮</span
                ><span class="youhui"
                  >优惠{{ Math.floor(item.coupon_info_money) }}元</span
                >
              </div>
              <div class="xiaoliang">
                销量<span
                  >{{ Math.floor(item.coupon_remain_count / 1000) }}万</span
                >
              </div>
            </div>
            <div class="btn"><button>领券购买</button></div>
          </div>
        </li>
      </ul>
    </div>
    <comp-nomore></comp-nomore>
  </div>
</template>

<script>
import compHeader from "@/components/comp-header.vue";
import compTitleSecond from "@/components/comp-title-second.vue";
import compNomore from "@/components/comp-nomore.vue";
export default {
  name: "Shopping",
  components: {
    compHeader: compHeader,
    compTitleSecond: compTitleSecond,
    compNomore: compNomore,
  },
  data() {
    return {
      searchley: "",
      arrsearch: [],
      arrrxsp: [],
      scrollTop3: 0,
    };
  },
  methods: {
    getDataSearch() {
      let url =
        "https://api.zhetaoke.com:10003/api/api_quanwang.ashx?appkey=3c11eb7345ed462dbcda235151c10781&page=1&page_size=8&type=2&sort=new&q=" +
        this.searchley;
      let pro = axios.get(url);
      pro.then((response) => {
        console.log(response);
        if (response.data.status == 200) {
          let res = response.data.content;
          let arr = [];
          res.forEach((item) => {
            let obj = {};
            obj.id = item.tao_id;
            obj.pict_url = item.pict_url; //图片
            arr.push(obj);
          });
          this.arrsearch = arr;
        }
      });
    },
    getData() {
      let pro = axios.get(
        "https://api.zhetaoke.com:10001/api/api_all.ashx?appkey=3c11eb7345ed462dbcda235151c10781&page=1&page_size=30&sort=new&today=1"
      );
      pro.then((response) => {
        if (response.data.status == 200) {
          let res = response.data.content;
          let arr = [];
          res.forEach((item) => {
            let obj = {};
            obj.id = item.tao_id;
            obj.pict_url = item.pict_url; //图片
            obj.title = item.title; //标题
            obj.coupon_info_money = item.coupon_info_money; //优惠券
            obj.coupon_remain_count = item.coupon_remain_count; //销量
            arr.push(obj);
          });
          this.arrrxsp = arr;
        }
      });
    },
  },
  mounted() {
    this.getData();
  },

  beforeRouteLeave(to, from, next) {
    this.scrollTop3 = document.documentElement.scrollTop || document.body.scrollTop;
    next();
  },
  beforeRouteEnter(to, from, next) {
    next((vm) => {
      window.scrollTo(0,vm.scrollTop3);
    });
  },
};
</script>

<style lang="scss" scoped>
.header {
  width: 100%;
  height: 180px;
  background: url(../assets/shopping.jpg) no-repeat;
  background-size: (1024px * (4/10)) (448px * (4/10));
  background-position: top center;
  .search {
    display: flex;
    position: absolute;
    top: 80px;
    left: 10px;
    font-size: 0;
    .shopping-car {
      font-size: 20px;
      color: #fff;
      padding: 0 10px;
    }
    .search-box {
      width: 300px;
      height: 25px;
      position: relative;
      border-radius: 12px;
      .search-icon {
        color: #ccc;
        font-size: 17px;
        position: absolute;
        top: 5px;
        left: 15px;
        z-index: 1000;
      }
      input {
        border: none;
        outline: none;
        width: 300px;
        height: 25px;
        text-indent: 40px;
        border-radius: 12px;
        font-size: 14px;
        position: absolute;
        top: 0;
      }
    }
  }
}
.types {
  width: 355px;
  height: 180px;
  padding: 0 21px;
  box-sizing: border-box;
  margin: 10px auto;
  ul {
    width: 100%;
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;
    li {
      margin-top: 20px;
      flex-basis: 20%;
      flex-flow: 1;
      flex-shrink: 0;
      text-align: center;
      a {
        .icon {
          display: block;
          margin-left: 10px;
          width: 70px * (5/10);
          height: 70px * (5/10);
          background: url(../assets/sprite2.png) no-repeat;
          background-size: (623px * (5/10)) (1016px * (5/10));
        }
        .text {
          display: block;
          margin-top: 10px;
          font-size: 12px;
        }
      }
    }
    li:nth-child(1) .icon {
      background-position: (-65px * (5/10)) (-185px * (5/10));
    }
    li:nth-child(2) .icon {
      background-position: (-200px * (5/10)) (-185px * (5/10));
    }
    li:nth-child(3) .icon {
      background-position: (-340px * (5/10)) (-185px * (5/10));
    }
    li:nth-child(4) .icon {
      background-position: (-470px * (5/10)) (-185px * (5/10));
    }
    li:nth-child(5) .icon {
      background-position: (-65px * (5/10)) (-325px * (5/10));
    }
    li:nth-child(6) .icon {
      background-position: (-200px * (5/10)) (-325px * (5/10));
    }
    li:nth-child(7) .icon {
      background-position: (-340px * (5/10)) (-325px * (5/10));
    }
    li:nth-child(8) .icon {
      background-position: (-470px * (5/10)) (-325px * (5/10));
    }
    li:nth-child(9) .icon {
      background-position: (-65px * (5/10)) (-465px * (5/10));
    }
    li:nth-child(10) .icon {
      background-position: (-200px * (5/10)) (-465px * (5/10));
    }
  }
}
.product-list {
  width: 100%;
  margin: 0 auto;
  padding: 0 10px;
  box-sizing: border-box;
  ul {
    width: 100%;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    li {
      margin-bottom: 10px;
      border-radius: 5px;
      overflow: hidden;
      flex-basis: 48%;
      height: 275px;
      box-shadow: 0 0 5px #ccc;
      font-size: 12px;
      .top {
        img {
          width: 100%;
          height: 180px;
        }
      }
      .bottom {
        padding: 10px 0;
        box-sizing: border-box;
        .product-name {
          color: #999;
          padding: 0 5px;
          box-sizing: border-box;
          margin-bottom: 10px;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
        }
        .youhui {
          height: 20px;
          line-height: 20px;
          display: flex;
          .quan {
            width: 110px;
            .baoyou {
              display: inline-block;
              color: #fff;
              padding: 0 5px;
              background-color: #42c076;
            }
            .youhui {
              display: inline-block;
              padding: 0 5px;
              color: #fff;
              background-color: #fb4d4d;
            }
          }
          .xiaoliang {
            width: 60px;
            text-align: center;
          }
        }

        .btn {
          width: 150px;
          margin: 10px auto;
          button {
            width: 148px;
            border: 1px solid #fb4d4d;
            color: #fb4d4d;
            border-radius: 5px;
          }
        }
      }
    }
  }
}
img[lazy=loading] {
  width: 100%;
  height: 100%;
   }
</style>